<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        @returnBack="returnBack"
        title="智能柜柜存明细"
      >
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <BasicInformation
              :info="infoList"
              :label-width="infoList.labelWidth"
            />
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip :text="$t('detailInfo')" :sums="tableInfo.sums" />
          </div>
          <div class="model-panel-body">
            <div class="flex_full_item">
              <!-- 表格 -->
              <PageTable
                v-model:query="filterInfo.query"
                v-model:data="tableInfo.data"
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                :pager="false"
                :api="tableInfo.api"
                :check-box="false"
                :tab-index="true"
                :field-list="tableInfo.fieldList"
                :isDynamic="true"
                :summary="true"
                :summary-field-list="tableInfo.summaryFieldList"
              >
                <template v-slot:col-orderNo="scope">
                  <span>{{ scope.row.orderNo }}</span>
                </template>
              </PageTable>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
  </div>
</template>

<script setup name="detail">
import {
  getSmartCabinetAccessRecordDetail,
  getSmartCabinetAccessRecordDetailList,
} from '@/api/smartCabinet.js'
import { getCustomizeSetting } from '@/api/customize'
const { proxy } = getCurrentInstance()
const emit = defineEmits()
const props = defineProps({
  visible: {
    type: Boolean,
    default: function () {
      return false
    },
  },
  tableRow: {
    type: Object,
    default: function () {
      return {}
    },
  },
})

const infoList = ref({
  data: {
    orderNo: '',
  },
  fieldList: [
    { label: '存取记录单号', value: 'orderNo', type: 'text' },
    { label: '智能柜编码', value: 'smartCabinetCode' },
    { label: '智能柜名称', value: 'smartCabinetName' },
    { label: '位置', value: 'smartCabinetAddress' },
    { label: '智能柜类型', value: 'smartCabinetTypeValue' },
    { label: '所属仓库', value: 'smartCabinetDepotName' },
    { label: '所属部门', value: 'smartCabinetDeptName' },
    { label: '存取账号', value: 'accessAccount' },
    { label: '存取人', value: 'accessUserName' },
    { label: '存取部门', value: 'accessDeptName' },
    { label: '存取时间', value: 'accessTime' },
    { label: '存取类型', value: 'accessTypeValue' },
  ],
  labelWidth: '110px',
})

// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  api: getSmartCabinetAccessRecordDetailList,
  data: [],
  fieldList: [],
  summaryFieldList: [
    { value: 'qty', formatter: proxy.$fn.qtyFormatter },
    { value: 'sumAmount', formatter: proxy.$fn.TripartiteMethod },
  ],
  handle: {},
})
const filterInfo = ref({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: null,
      },
    },
    queryParams: {
      orderId: '',
    },
  },
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})

onMounted(() => {
  filterInfo.value.query.queryMap.orderId.value = props.tableRow.id
  filterInfo.value.query.queryParams.orderId = props.tableRow.id
  let obj = {}
  tableInfo.value.fieldList = Object.values({
    ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
    ...obj,
  })
  getMain()
  getCustomize()
})

function returnBack() {
  emit('returnBack', false)
}
function getCustomize() {
  let param = {
    tableKey:
      'smartCabinetAccessRecordOrderDetail-com.slip.spd.entity.vo.smartCabinet.SmartCabinetAccessRecordDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      tableInfo.value.fieldList = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail
      )
      filterInfo.value.query.customizeUserVO = data
      getList()
    }
  })
}
function getMain() {
  getSmartCabinetAccessRecordDetail(props.tableRow.id).then((resp) => {
    if (resp && resp.success) {
      infoList.value.data = resp.data
    }
  })
}
function getList() {
  tableInfo.value.refresh = Math.random()
}
</script>

<style scoped lang="scss">
:deep(.table-scroll-hidden > .el-table) {
  overflow-y: hidden;
}
</style>
